namespace ArivisTests.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitTestModel : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.UserProfile",
                c => new
                {
                    UserId = c.Int(nullable: false, identity: true),
                    UserName = c.String(nullable: false),
                })
                .PrimaryKey(t => t.UserId);

            CreateTable(
                "dbo.TestPlan",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.TestScenario",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        Url = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.TestCase",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Scenario_Id = c.Int(nullable: false),
                        User_UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.TestScenario", t => t.Scenario_Id, cascadeDelete: true)
                .ForeignKey("dbo.UserProfile", t => t.User_UserId, cascadeDelete: true)
                .Index(t => t.Scenario_Id)
                .Index(t => t.User_UserId);
            
            CreateTable(
                "dbo.TestRun",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        Date = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.TestScenarioTestPlans",
                c => new
                    {
                        TestScenario_Id = c.Int(nullable: false),
                        TestPlan_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.TestScenario_Id, t.TestPlan_Id })
                .ForeignKey("dbo.TestScenario", t => t.TestScenario_Id, cascadeDelete: true)
                .ForeignKey("dbo.TestPlan", t => t.TestPlan_Id, cascadeDelete: true)
                .Index(t => t.TestScenario_Id)
                .Index(t => t.TestPlan_Id);
            
            CreateTable(
                "dbo.TestRunTestCases",
                c => new
                    {
                        TestRun_Id = c.Int(nullable: false),
                        TestCase_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.TestRun_Id, t.TestCase_Id })
                .ForeignKey("dbo.TestRun", t => t.TestRun_Id, cascadeDelete: true)
                .ForeignKey("dbo.TestCase", t => t.TestCase_Id, cascadeDelete: true)
                .Index(t => t.TestRun_Id)
                .Index(t => t.TestCase_Id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.TestRunTestCases", new[] { "TestCase_Id" });
            DropIndex("dbo.TestRunTestCases", new[] { "TestRun_Id" });
            DropIndex("dbo.TestScenarioTestPlans", new[] { "TestPlan_Id" });
            DropIndex("dbo.TestScenarioTestPlans", new[] { "TestScenario_Id" });
            DropIndex("dbo.TestCase", new[] { "User_UserId" });
            DropIndex("dbo.TestCase", new[] { "Scenario_Id" });
            DropForeignKey("dbo.TestRunTestCases", "TestCase_Id", "dbo.TestCase");
            DropForeignKey("dbo.TestRunTestCases", "TestRun_Id", "dbo.TestRun");
            DropForeignKey("dbo.TestScenarioTestPlans", "TestPlan_Id", "dbo.TestPlan");
            DropForeignKey("dbo.TestScenarioTestPlans", "TestScenario_Id", "dbo.TestScenario");
            DropForeignKey("dbo.TestCase", "User_UserId", "dbo.UserProfile");
            DropForeignKey("dbo.TestCase", "Scenario_Id", "dbo.TestScenario");
            DropTable("dbo.TestRunTestCases");
            DropTable("dbo.TestScenarioTestPlans");
            DropTable("dbo.TestRun");
            DropTable("dbo.TestCase");
            DropTable("dbo.TestScenario");
            DropTable("dbo.TestPlan");
        }
    }
}
